package com.jams.goodox.activity.home;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jams.goodox.BaseActivity;
import com.jams.goodox.R;
import com.jams.goodox.adapter.CustomFragmentPagerAdapter;
import com.jams.goodox.net.BaseEntity;
import com.jams.goodox.net.RetrofitCallbackListener;
import com.jams.goodox.net.services.HomeService;
import com.jams.goodox.utils.permission.PhoneUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;
import retrofit2.Call;

/**
 * Created by Administrator on 2017/10/4.
 */

public class GoodDetailActivity extends BaseActivity {


    @Bind(R.id.iv_back)
    ImageView ivBack;
    @Bind(R.id.head_info)
    ImageView headInfo;
    @Bind(R.id.ler_save)
    LinearLayout lerSave;
    @Bind(R.id.tab_layout)
    TabLayout tabLayout;
    @Bind(R.id.linear_bottom)
    LinearLayout linearBottom;
    @Bind(R.id.viewPager)
    ViewPager viewPager;
    @Bind(R.id.tx_join_buyCar)
    TextView tx_join_buyCar;

    private List<Fragment> fragmentList;
    private List<String> tabsTitle;
    private String id;

    public static void startActvity(Context context,String id){
        Intent in=new Intent(context,GoodDetailActivity.class);
        in.putExtra("id",id);
        context.startActivity(in);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.good_detail_actiivty;
    }

    @Override
    protected void init() {
        setTitleVisibility(false);
        id=getIntent().getStringExtra("id");
        fragmentList=new ArrayList<>();
        tabsTitle=new ArrayList<>();
        Bundle bundle=new Bundle();
        bundle.putString("id",getIntent().getStringExtra("id"));
        GoodFragment fragment1= new GoodFragment();
        fragment1.setArguments(bundle);
        GoodPicFragment fragment2= new GoodPicFragment();
        fragment2.setArguments(bundle);
        CommentFragment fragment3= new CommentFragment();
        fragment3.setArguments(bundle);
        fragmentList.add(fragment1);
        tabsTitle.add("商品");
        fragmentList.add(fragment2);
        tabsTitle.add("详情");
        fragmentList.add(fragment3);
        tabsTitle.add("评价");

        viewPager.setAdapter(new CustomFragmentPagerAdapter(getSupportFragmentManager(), tabsTitle, fragmentList));


        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);

        viewPager.setOffscreenPageLimit(2);
    }

    @OnClick({R.id.my_back, R.id.title_right,R.id.img_bug_car,R.id.tx_join_buyCar,R.id.tx_buy,R.id.textView3,R.id.img_main})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.my_back:
                finish();
                break;
            case R.id.title_right:
                break;
            case R.id.img_bug_car:
                Intent in=new Intent(this,BuyCarActivity.class);
                in.putExtra("id",id);
                startActivity(in);
                break;
            case R.id.tx_join_buyCar:
            case R.id.tx_buy:
                in=new Intent(this,BuyCarDialogActivity.class);
                in.putExtra("id",id);
                startActivity(in);
                break;
            case R.id.textView3:
                new PhoneUtils(this).makeCall("客服","057987071703");
                break;
            case R.id.img_main:
                qStartActivity(HomeActivity.class);
                break;
        }
    }

    private void joinBuyCar(){
        enqueue(createCallService(HomeService.class).joinShopCart(new HashMap<String, String>()), new RetrofitCallbackListener<BaseEntity>() {
            @Override
            public void onSuccess(Call<BaseEntity> call, BaseEntity result) {
            }

            @Override
            public void onError(String msg) {

            }
        });
    }
}
